define(function(require, exports, module) {
    function initArticleImg() {
        $('.list-img img').each(function() {
            var obj = $(this);
            var src = obj.attr('data-src');
            if (!src) {
                return;
            }
            src = src.replace(/_800/, '_200');
            var img = new Image();
            img.onload = function() {
                obj.attr('src', src);
                var w = obj.width();
                var h = obj.height();
                if (w >= h) {
                    obj.css({'height': '100%'});
                } else {
                    obj.css({'width': '100%'});
                }
            }
            img.src = src;
        });
    }
    exports.init = function() {
        initArticleImg();
        $('.js-article-del').on('click', function() {
            if (!confirm('你确定要删除吗？')) {
                return;
            }
            var articleId = $(this).attr('articleId');
            $.ajax({
                url: '/Ajax/Article/del',
                type: 'post',
                data: {articleId: articleId},
                dataType: 'json',
                success: function(d) {
                    if (d.error) {
                        alert(d.data);
                    } else {
                        window.location.reload();
                    }
                }
            });
        });
    }
});